package com.woniu.model;

import com.github.pagehelper.PageInfo;
import lombok.Data;

import java.util.List;
import java.util.Map;
import java.util.Set;

@Data
public class Result<T> {
    private Integer code;
    private String msg;
    private T data;

    public Integer getCode() {
        return code;
    }

    public Result<T> setCode(Integer code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public Result<T> setMsg(String msg) {
        this.msg = msg;
        return this;
    }



    public Result<T> setData(T data) {
        this.data = data;
        return this;
    }

    public static <S> Result<S> getResult(Class<S> type) {
        Result<S> result = new Result<>();
        result.setCode(200);
        result.setMsg("访问成功");
        return result;
    }

    public static <S> Result<S> getResult() {
        Result<S> result = new Result<>();
        result.setCode(200);
        result.setMsg("访问成功");
        return result;
    }

    public static <S> Result<List<S>> getListResult(Class<S> type) {
        Result<List<S>> result = new Result<>();
        result.setCode(200);
        result.setMsg("访问成功");
        return result;
    }

    public static <S> Result<Set<S>> getSetResult(Class<S> type) {
        Result<Set<S>> result = new Result<>();
        result.setCode(200);
        result.setMsg("访问成功");
        return result;
    }

    public static <S> Result<PageInfo<S>> getPageInfoResult(Class<S> type) {
        Result<PageInfo<S>> result = new Result<>();
        result.setCode(200);
        result.setMsg("访问成功");
        return result;
    }

    public static <K, V> Result<Map<K, V>> getMapResult(Class<K> typeK, Class<V> typeV) {
        Result<Map<K, V>> result = new Result<>();
        result.setCode(200);
        result.setMsg("访问成功");
        return result;
    }

    public static <K, V> Result<Map<K, List<V>>> getMapListResult(Class<K> typeK, Class<V> typeV) {
        Result<Map<K, List<V>>> result = new Result<>();
        result.setCode(200);
        result.setMsg("访问成功");
        return result;
    }
}
